package com.fs.controller;

import com.fs.producer.Demo01Producer;
import org.apache.rocketmq.client.producer.SendResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * @author ：hyq
 * @date ：Created in 2020/5/21 18:13
 * @description：
 * @modified By：
 */
@RestController
public class RocketController {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private Demo01Producer producer;

    /**
     * 测试批量发送
     * @throws InterruptedException
     */
    @GetMapping("send")
    public void testSendBatch() throws InterruptedException {
        List<Integer> ids = Arrays.asList(1, 2, 3);
        SendResult result = producer.sendBatch(ids);
        logger.info("[testSendBatch][发送编号：[{}] 发送结果：[{}]]", ids, result);

        // 阻塞等待，保证消费
        new CountDownLatch(1).await();
    }

    @GetMapping("syncSend")
    public void syncSend(){
        SendResult result = producer.syncSend(22);
        logger.info("[testSendBatch][发送编号：[{}] 发送结果：[{}]]", 22, result);
    }


}
